import './assets/main.css'

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

// 初始化一些模拟数据，方便演示
const initializeMockData = () => {
  // 检查是否已有用户数据
  if (!localStorage.getItem('users')) {
    const mockUsers = [
      {
        id: '1',
        username: 'user1',
        password: '123456',
        createdAt: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
        items: []
      },
      {
        id: '2',
        username: 'user2',
        password: '123456',
        createdAt: new Date(Date.now() - 14 * 24 * 60 * 60 * 1000).toISOString(),
        items: []
      }
    ]
    localStorage.setItem('users', JSON.stringify(mockUsers))
  }

  // 检查是否已有商品数据
  if (!localStorage.getItem('items')) {
    const mockItems = [
      {
        id: '1001',
        name: '二手iPhone 12',
        price: 3500,
        description: '9成新，无拆修，电池健康85%，送充电器和数据线',
        image: 'https://picsum.photos/seed/iphone12/400/300',
        sellerId: '1',
        sellerName: 'user1',
        createdAt: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString()
      },
      {
        id: '1002',
        name: '机械键盘',
        price: 150,
        description: '青轴机械键盘，使用一年，按键灵敏，无损坏',
        image: 'https://picsum.photos/seed/keyboard/400/300',
        sellerId: '2',
        sellerName: 'user2',
        createdAt: new Date(Date.now() - 5 * 24 * 60 * 60 * 1000).toISOString()
      },
      {
        id: '1003',
        name: '《哈利波特》全套书籍',
        price: 200,
        description: '中文版全套7本，保存完好，几乎全新',
        image: 'https://picsum.photos/seed/books/400/300',
        sellerId: '1',
        sellerName: 'user1',
        createdAt: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000).toISOString()
      },
      {
        id: '1004',
        name: '自行车',
        price: 450,
        description: '山地自行车，26寸，铝合金车架，车况良好',
        image: 'https://picsum.photos/seed/bike/400/300',
        sellerId: '2',
        sellerName: 'user2',
        createdAt: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString()
      }
    ]
    localStorage.setItem('items', JSON.stringify(mockItems))
  }
}

// 初始化模拟数据
initializeMockData()

// 创建并挂载Vue应用
const app = createApp(App)
app.use(router)
app.mount('#app')
